package com.cloud.socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * @version v1.0
 * @author: TianXiang
 * @description: 处理OA主动请求的消息体
 * @date: 2020/11/5
 */

public class OAMsgTask implements Runnable{
    private static final Logger LOG = LoggerFactory.getLogger(OAMsgTask.class.getName());

    private final String CHARSET = "utf-8";

    private final String RESPONSE_MSG_TEMPLATE = "0000000010                                   A01789     710     0000         <?xml version=\"1.0\" encoding=\"utf-8\"?><res><head><status>%s</status><msg>%s</msg></head></res>";

    private int userId;

    private String tenantCode;

    private String token;


    private Socket socket;

    public OAMsgTask(int userId, String tenantCode, String token, Socket socket) {
        this.userId = userId;
        this.tenantCode = tenantCode;
        this.token = token;
        this.socket = socket;
    }

    @Override
    public void run() {
        BufferedInputStream inputStream = null;
       try {
           inputStream = new BufferedInputStream(socket.getInputStream());
           byte[] bytes = new byte[9999];
           while (-1 != inputStream.read(bytes)){
               String responseXML = new String(bytes).trim();
               LOG.info("收到OA主动请求的消息体: {}", responseXML);

           }
       }catch (Exception e) {
           LOG.error(e.getMessage());
       }finally {
           try {
               inputStream.close();
           } catch (IOException e) {
               LOG.info("处理OA消息任务关闭IO流失败: {}", e.getMessage());
           }
       }
    }




}
